#!/usr/bin/env python
# coding:utf-8
"""
Created on 2017/7/10 18:08

base Info
"""
__author__ = 'kumikoda'
__version__ = '1.0'

import sys
reload(sys)
sys.setdefaultencoding('utf8')

from modules import dbs

#from modules.xlrd import XLRD




class Inquire(object):
    def __init__(self):
        self.conn, self.cur = dbs.db_connect()

        #self.xls = XLRD(r'The_assets_total_20170609_AWS_AE.xlsx')

        #self.xls = XLRD.load_excel(self.xls)



    # 主机分类查询
    def inquire(self, sql):
        query = '''
        SELECT
            c.id,
            c.assets_number,
            country,
            IDC_type,
            room_info,
            cabinet_info,
            serial_number,
            model_number,
            wan_ip,
            ip,
            remote_ip,
            status,
            assets_user,
            business_type,
            business_name,
            detailed_action,
            upline_time,
            downline_time,
            osystem,
            source,
            deadline,
            contract_number,
            m.price,
            m.monthly_fee,
            up_time,
            down_time,
            m.usage_days,
            m.monthbilling,
            comment,
            cpu,
            mem,
            disk
        FROM
            cmdb AS c,
            money AS m 
        
        WHERE
            c.assets_number = m.assets_number
        AND '''


        query += '%s' % sql ## SQL语句拼接，在and后面，如有则能够查询，没有报语句错误
        print query
        #self.xls.load_excel()
        self.cur.execute(query)
        data = self.cur.fetchall()
        return {'code': 61, 'message': '主机查询成功', 'data': data}

def main():
    i = Inquire()
    i.inquire('c.assets_number = \'efun-cloudAWS-00881\' ')


if __name__ == '__main__':
    main()